The C programming language is a relatively small and simple language, used for a wide range of applications. C is relatively portable, despite its rich set of low level operations. Implementations of C are available on most computers and operating systems, ranging from supercomputers to microcomputers. The characteristics of C are described in a reference book entitled The C Programming Language, by Brian Kernighan and Dennis Ritchie, which is widely accepted by users of C, and its subsequent edition. In very general terms, some basic characteristics are easily identifiable. C supports the use of functions. Argument passing is by value, although a call by reference can be achieved by passing addresses of arguments. Variables can be static, automatic, or external. C is a typed language, supporting a number of data types; for example, integers, characters, and floating point numbers with various lengths. A powerful feature of C is the use of variables to hold addresses in the form of a pointer, which is defined in C as a variable containing the address of another variable. Arrays can be defined to hold a number of items of information of the same data type.
C permits the use of structures, which permit a program to operate on data items of different types together as a unit. As defined by Kernighan and Ritchie, a structure is a collection of one or more variables, possibly of different types, grouped together under a single name for convenience. A C structure is analogous to a "record" of other languages, such as Pascal.
The efficient use of structures is becoming more important with expanding applications of C, notably the use of variations of C for object oriented programming. Yet, a particularly inefficient use of structures has been the manner in which they are returned from functions. Typical programming methods cause all functions that return a structure to be processed in the same manner. An area of memory is statically allocated at link time for storing the structure. The called function copies the returned structure into that area, then the caller copies the returned structure out of that area. This method requires two copies of the structure.
Another problem with the above method for returning structures is that the method is not re-entrant. Some methods have provided for re-entrancy by creating a buffer in the local frame of the caller, passing the buffer address to the caller, and requiring the called function to copy the return structure to the buffer. Nevertheless, this method does not cure the problem of redundant copying.
Thus, a need exists for an efficient way to return structures from functions. A method that eliminates the redundancy of making more than one copy would greatly improve the speed of execution of functions that return structures. Furthermore, in addition to avoiding unnecessary copying, the method should permit re-entrancy.